s=[1 1 1 2 2 3 3 4 5 5 6 7];
t=[2 4 8 3 7 4 6 5 6 8 7 8];
weights=[10 10 1 10 1 10 1 1 12 12 12 12];
names={'1' '2' '3' '4' '5' '6' '7' '8'};
EdgeTable=table([s' t'],weights','VariableNames',{'EndNodes' 'Weights'});
NodeTable=table(names','VariableNames',{'Name'});
% EdgeTable =
% 
%   12×2 table
%     EndNodes    Weights
%     ________    _______
%      1    2       10   
%      1    4       10   
%      1    8        1   
%     ...  ...     ...   
%      6    7       12   
%      7    8       12   
G=graph(EdgeTable,NodeTable);
p=plot(G,'EdgeLabel',weights)

T=minspantree(G,'Method','dense');      % 'dense'为Prim算法,'sparse'为Kruskal算法
highlight(p,T,"EdgeColor",'r','LineWidth',2.5);
L = sum(T.Edges.Weights)     % 对最小生成树的边的权重求和
